import store, { incrementAction, decrementAction } from "./store";

function App() {
  // 读取数据
  const count = store.getState();

  const handleIncrement = () => {
    // 调用action函数生成action对象
    const action = incrementAction(1);
    // 调用dispatch方法传入action对象，此时就会触发reducer，reducer函数会计算生成新状态
    store.dispatch(action);
  };

  const handleDecrement = () => {
    store.dispatch(decrementAction(1));
  };

  return (
    <div>
      <p>count: {count}</p>
      <button onClick={handleIncrement}>+</button>
      <button onClick={handleDecrement}>-</button>
    </div>
  );
}

export default App;
